// AdminLTE Gruntfile
module.exports = function (grunt) {

  'use strict';

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
      // If any .less file changes in directory "src/build/less/" run the "less"-task.
      files: ["src/build/less/*.less", "src/build/less/skins/*.less", "src/build/js/*.js","src/build/js/*/*.js"],
      tasks: ["less", "uglify"]
    },
    // "less"-task configuration
    // This task will compile all less files upon saving to create both AdminLTE.css and AdminLTE.min.css
    less: {
      // Development not compressed
      development: {
        options: {
          // Whether to compress or not 是否压缩
          compress: true
        },
        files: {
          // compilation.css  :  source.less
          "src/dist/css/AdminLTE.min.css": "src/build/less/AdminLTE.less",
          // AdminLTE without plugins
          "src/dist/css/alt/AdminLTE-without-plugins.css": "src/build/less/AdminLTE-without-plugins.less",
          // Separate plugins
          "src/dist/css/alt/AdminLTE-select2.css": "src/build/less/select2.less",
          "src/dist/css/alt/AdminLTE-fullcalendar.css": "src/build/less/fullcalendar.less",
          "src/dist/css/alt/AdminLTE-bootstrap-social.css": "src/build/less/bootstrap-social.less",
          //Non minified skin files
          "src/dist/css/skins/_all-skins.min.css": "src/build/less/skins/_all-skins.less",
        }
      },
    },
    // Optimize images
    image: {
      dynamic: {
        files: [{
          expand: true,
          cwd: 'src/build/img/',
          src: ['**/*.{png,jpg,gif,svg,jpeg}'],
          dest: 'src/dist/img/'
        }]
      }
    },

    // Validate JS code
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      core: {
        src: 'src/dist/js/app.js'
      },
      demo: {
        src: 'src/dist/js/demo.js'
      },
      pages: {
        src: 'src/dist/js/pages/*.js'
      }
    },

    // Validate CSS files
    csslint: {
      options: {
        csslintrc: 'src/build/less/.csslintrc'
      },
      dist: [
        'src/dist/css/AdminLTE.css'
      ]
    },

    // Validate Bootstrap HTML
    bootlint: {
      options: {
        relaxerror: ['W005']
      },
      files: ['src/pages/**/*.html', '*.html']
    },

    // Delete images in build directory
    // After compressing the images in the src/build/img dir, there is no need
    // for them
    clean: {
      build: ["src/build/img/*"]
    },
    //配置本地服务
    connect: {
      server: {
          options: {
              protocol: 'http',
              port: 8000,
              hostname: '*',
              keepalive: true,
              base: ['src/']
          }
      }
  }
  });

  // Load all grunt tasks

  // LESS Compiler
  grunt.loadNpmTasks('grunt-contrib-less');
  // Watch File Changes
  grunt.loadNpmTasks('grunt-contrib-watch');
  // Compress JS Files
  grunt.loadNpmTasks('grunt-contrib-uglify');
  // Optimize images
  grunt.loadNpmTasks('grunt-image');
  // Validate JS code
  grunt.loadNpmTasks('grunt-contrib-jshint');
  // Delete not needed files
  grunt.loadNpmTasks('grunt-contrib-clean');
  // Lint CSS
  grunt.loadNpmTasks('grunt-contrib-csslint');
  // Lint Bootstrap
  grunt.loadNpmTasks('grunt-bootlint');

  //配置本地服务
  grunt.loadNpmTasks('grunt-contrib-connect');


  // Linting task
  grunt.registerTask('lint', ['jshint', 'csslint', 'bootlint']);

  // The default task (running "grunt" in console) is "watch"
  grunt.registerTask('default', ['connect','watch']);

  
 
};
